<?php
    include('./library/conn.php');

    $password = $_REQUEST['user_pw'];
    $email = $_REQUEST['user_email'];
    $phone = $_REQUEST['user_tel'];
    $country = $_REQUEST['c_ountry'];
    $year = $_REQUEST['y_ear'];
    $month = $_REQUEST['m_onth'];
    $day = $_REQUEST['d_ay'];
    if($email){
        $select="select * from users where email=$email";
        $phone='';
    }else{
        $select="select * from users where phone=$phone";
        $email ='';
    }
    $result=$mysqli->query($select);
    if($result->num_rows>0){
        echo '<script>alert("用户已存在,请勿重复注册！");</script>';
        echo '<script>location.href="../src/html/reg.html";</script>';
        $mysqli->close();  //关闭数据库连接
        die();//终止代码
    }
    $insert = "insert into users (username,password,country,email,year,month,day,phone) values ('','$password','$country','$email','$year','$month','$day','$phone')";
    
    $res = $mysqli->query($insert);
    $mysqli->close();
    if($res){
        echo '<script>alert("用户注册成功,即将进入登录页面！");</script>';
        echo '<script>location.href="../src/html/login.html"</script>';
    }
?>